﻿using Manon.Admin.Web.ApplicationCore.Dtos.Settings;
using Manon.Admin.Web.ApplicationCore.Interfaces;
using Manon.Autofac;
using Manon.Core.Commons;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Manon.Admin.Web.Controllers
{
    public class SettingsController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 基本设置
        /// </summary>
        /// <returns></returns>
        public IActionResult BaseIndex()
        {
            return View();
        }

        /// <summary>
        /// 安全设置
        /// </summary>
        /// <returns></returns>
        public IActionResult Safe()
        {
            return View();
        }

        /// <summary>
        /// 邮件设置
        /// </summary>
        /// <returns></returns>
        public IActionResult Email()
        {
            return View();
        }

        /// <summary>
        /// 其他设置
        /// </summary>
        /// <returns></returns>
        public IActionResult Other()
        {
            return View();
        }


        #region 基本设置相关
        /// <summary>
        /// 获取用户基本设置
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<GetBaseSettingsOutput> GetBaseSettings()
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.GetBaseSettings( );

            return result;
        }

        /// <summary>
        /// 保存基本设置
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SaveBaseSettings([FromBody]SaveBaseSettingsInput Input)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.SaveBaseSettings(Input);

            return result;
        }
        #endregion

        #region 安全设置相关
        /// <summary>
        /// 获取用户基本安全设置
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<GetBaseSafeSettingsOutput> GetSafesettings()
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.GetSafesettings();

            return result;
        }

        /// <summary>
        /// 保存基本安全设置
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SaveBaseSafeSettings([FromBody] SaveBaseSafeSettingsInput Input)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.SaveBaseSafeSettings(Input);

            return result;
        }
        #endregion

        #region 邮件设置相关
        /// <summary>
        /// 获取用户基本邮件设置
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<GetBaseEmailSettingsOutput> GetEmailSettings()
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.GetEmailSettings();

            return result;
        }

        /// <summary>
        /// 保存基本邮件设置
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SaveBaseEmailSettings([FromBody] SaveBaseEmailSettingsInput Input)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.SaveBaseEmailSettings(Input);

            return result;
        }
        #endregion


    }
}
